﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stauffware.Common.Core
{
	//#################################################################################
	/// <summary>
	/// Parser for signed ushort values (System.Int16).
	/// </summary>

	public class Int16Parser : IntegerParser<short,Int16Parse>
	{ 
		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		public Int16Parser ( ) : base(DefaultParseOptions, null) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		public Int16Parser (NumberParseOptions options) : base(options, null) { }

		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		/// <param name="ifp">formatting info, or null</param>
		public Int16Parser (IFormatProvider ifp) : base(NumberParseOptions.None, ifp) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		/// <param name="ifp">formatting info, or null</param>
		public Int16Parser (NumberParseOptions options, IFormatProvider ifp) : base(options, ifp) { }

		/// <summary>
		/// Gets the maximum number of digits (base 10) that a number can have.
		/// </summary>
		protected override int MaxDigits { get { return 5; } }

		/// <summary>
		/// Gets the maximum number of digits that can appear in an exponent.
		/// </summary>
		protected override int MaxExponentDigits { get { return 2; } }

		/// <summary>
		/// Gets whether this parser's target type is signed.
		/// </summary>
		protected override bool Signed { get { return true; } }

	//	/// Creates a Parse object of the proper class for this Parser.
	//	protected override IntegerParse<short> CreateParseObject ()
	//	{ return new Int16Parse(); }

		/// <summary>
		/// Attempts a parse of a normalized integer string.  (see IntegerParser.TryParse)
		/// </summary>
		protected override bool TryParse (string str, out short value)
		{ return short.TryParse(str, out value); }

	}

	//=================================================================================
	/// <summary>
	/// Encapsulates the result of trying to parse a string into an short value.
	/// </summary>

	public class Int16Parse : IntegerParse<short>
	{
	}

	//#################################################################################
	/// <summary>
	/// Parser for unsigned ushort values (System.UInt16).
	/// </summary>

	public class UInt16Parser : IntegerParser<ushort,UInt16Parse>
	{
		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		public UInt16Parser ( ) : base(DefaultParseOptions, null) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		public UInt16Parser (NumberParseOptions options) : base(options, null) { }

		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		/// <param name="ifp">formatting info, or null</param>
		public UInt16Parser (IFormatProvider ifp) : base(NumberParseOptions.None, ifp) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		/// <param name="ifp">formatting info, or null</param>
		public UInt16Parser (NumberParseOptions options, IFormatProvider ifp) : base(options, ifp) { }

		/// <summary>
		/// Gets the maximum number of digits (base 10) that a number can have.
		/// </summary>
		protected override int MaxDigits { get { return 5; } }

		/// <summary>
		/// Gets the maximum number of digits that can appear in an exponent.
		/// </summary>
		protected override int MaxExponentDigits { get { return 2; } }

		/// Gets whether this parser's target type is signed.
		protected override bool Signed { get { return false; } }

	//	/// Creates a Parse object of the proper class for this Parser.
	//	protected override IntegerParse<ushort> CreateParseObject ()
	//	{ return new UInt16Parse(); }

		/// Attempts a parse of a normalized integer string.  (see IntegerParser.TryParse)
		protected override bool TryParse (string str, out ushort value)
		{ return ushort.TryParse(str, out value); }
	}

	//=================================================================================
	/// <summary>
	/// Encapsulates the result of trying to parse a string into a ushort value.
	/// </summary>

	public class UInt16Parse : IntegerParse<ushort>
	{
	}

	//#################################################################################
}
